
package cn.gz3c.uitest.view;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.LinearGradient;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.graphics.RectF;
import android.graphics.Shader.TileMode;
import android.view.MotionEvent;

import com.huawei.hms.audioeditor.sdk.asset.HAEAudioAsset;
import com.huawei.hms.audioeditor.sdk.bean.HAEAudioVolumeObject;
import com.huawei.hms.audioeditor.sdk.util.SmartLog;
import com.huawei.hms.audioeditor.ui.R.drawable;
import com.huawei.hms.audioeditor.ui.common.utils.d;

import java.util.ArrayList;
import java.util.List;

import cn.gz3c.uitest.viewmodel.EditPreviewViewModel;
import cn.gz3c.uitest.Util;

@SuppressLint("ViewConstructor")
public class WaveMasterTrackView extends BaseWaveTrackView {
    private final Paint fa;
    private final Paint ga;
    private final List<Float> ha = new ArrayList<>();
    private final boolean[] ia = new boolean[]{false};
    private boolean ja = true;
    private float ka = 0.0F;
    private int la;
    private boolean na;
    private boolean oa;
    private Bitmap pa;
    private double qa;
    private double ra;
    private int sa;
    private int ta;
    private final int va;
    private int wa;
    private final double xa;

    public WaveMasterTrackView(Activity var1, EditPreviewViewModel var2, int var3, int var4) {
        super(var1, var2, 1);
        this.la = this.m() + super.a;
        double ma = 400.0D;
        int ua = 50;
        int var7;
        this.va = var7 = ua;
        this.xa = ma + (double) var7;
        int aa1;
        int ba;
        aa1 = var3;
        ba = var4;
        this.ga = new Paint();
        this.ga.setAntiAlias(true);
        this.ga.setColor(Color.parseColor("#FF0D0326"));
        this.ga.setStyle(Style.FILL_AND_STROKE);
        var7 = super.l;
        byte var8;
        if (var7 <= 1) {
            var8 = 8;
        } else {
            var8 = 5;
        }

        this.ga.setStrokeWidth((float) var8);

        this.fa = new Paint();
        this.fa.setAntiAlias(true);
        LinearGradient var10;

        int var9 = aa1;
        var3 = ba;
        TileMode var14 = TileMode.MIRROR;
        var10 = new LinearGradient(0.0F, 0.0F, 5.0F, 100.0F, var9, var3, var14);
        this.fa.setStyle(Style.FILL_AND_STROKE);
        this.fa.setShader(var10);
        this.fa.setStrokeWidth(5.0F);
        if (this.pa == null) {
            this.pa = BitmapFactory.decodeResource(this.getResources(), drawable.line_control);
        }

        WaveMasterTrackView var10000 = this;
        WaveMasterTrackView var10001 = this;
        WaveMasterTrackView var10002 = this;
        WaveMasterTrackView var10003 = this;
        WaveMasterTrackView var15 = this;
        this.sa = this.pa.getHeight();
        this.ta = this.pa.getWidth();
        int ya = var7 = this.ta;
        int za = var9 = this.sa;
        var3 = ya;
        float var12 = (float) var3 / (float) var7;
        float var11 = (float) za / (float) var9;
        Matrix var13;
        Matrix var10006 = var13 = new Matrix();
        var10006.postScale(var12, var11);
        Bitmap var10005 = this.pa;
        WaveMasterTrackView var6 = this;
        int var5 = this.ta;
        var7 = var6.sa;
        var15.pa = Bitmap.createBitmap(var10005, 0, 0, var5, var7, var13, true);
        var10002.sa = var10003.pa.getHeight();
        var10000.ta = var10001.pa.getWidth();
    }

    private float a(HAEAudioVolumeObject var1) {
        WaveMasterTrackView var10000 = this;
        float var2 = (float) var1.getMaxValue();
        int var3 = var1.getVolume();
        return (float) (Math.abs(var10000.getMeasuredHeight()) / 2 * var3) / var2;
    }

    static {
        WaveMasterTrackView.class.getSimpleName();
    }

    protected void onMeasure(int var1, int var2) {
        super.onMeasure(var1, var2);
        this.b(var2);
    }

    protected void onDraw(Canvas var1) {
        int var2 = this.getMeasuredHeight();
        RectF var3;

        float var10002 = (float) (this.m() + super.a);
        float var10003 = (float) Util.dip2px(3.0F);
        double var4 = (double) (this.m() + super.a);
        var3 = new RectF(var10002, var10003, (float) (this.j() + var4), (float) var2);
        if (this.ja) {
            this.ka = (var3.right - var3.left) / (float) super.r;
        }

        super.onDraw(var1);
        float var8 = var3.centerY();
        float var9 = var3.left;
        if (this.ja) {
            this.la = this.m() + super.a;
        }

        if (super.K != null) {
            super.J.clear();
            super.J.addAll(super.K);
        }

        if (super.J.size() > 0) {

            for (HAEAudioVolumeObject haeAudioVolumeObject : super.J) {
                HAEAudioVolumeObject var6;
                if ((var6 = haeAudioVolumeObject) != null) {
                    float var7 = (float) this.la;
                    if (!((var7 = Math.max(var9, (float) (var6.getTime() - super.W) * this.ka + var7)) < var3.left)) {
                        if (var7 > var3.right) {
                            break;
                        }

                        var1.drawLine(var7, var8 - this.a(var6), var7, var8 + this.a(var6), this.fa);
                    }
                }
            }

            super.J.clear();
            int var10;
            int var11 = (var10 = Util.dip2px(1.0F)) / 2;
            float var10005 = (float) this.la;
            float var10006 = var8 - (var9 = (float) var10);
            var1.drawLine(var10005, var10006, var3.right, var10006, this.fa);
            var1.drawLine((float) this.la, var8 + (float) var11, (float) getWidth(), var8 + (float) var11, this.ga);
            var1.drawLine((float) this.la, var8 + var9, var3.right, var8 + var9, this.fa);
        }

    }

    @SuppressLint("ClickableViewAccessibility")
    public boolean onTouchEvent(MotionEvent var1) {
        float var2 = var1.getX();
        float var3 = var1.getY();
        int var4;
        if ((var4 = var1.getAction()) != 0) {
            label93:
            {
                if (var4 != 1) {
                    if (var4 == 2) {
                        if (this.na) {
                            int var8;
                            if ((double) var2 <= this.ra - (double) (var8 = this.ta) && var2 >= (float) ((var4 = this.va) - var8 / 2)) {
                                this.qa = (double) ((int) var2);
                                if (this.qa < (double) var4) {
                                    this.qa = (double) var4;
                                }

                                this.postInvalidate();
                            }
                        } else {
                            int var5;
                            double var9;
                            if (this.oa && (var9 = (double) var2) >= this.qa + (double) (var5 = this.ta) && var9 <= (var9 = this.xa) + (double) ((float) var5 / 2.0F)) {
                                this.ra = (double) ((int) var2);
                                if (this.ra > var9) {
                                    this.ra = var9;
                                }

                                this.postInvalidate();
                            }
                        }
                        break label93;
                    }

                    if (var4 != 6) {
                        break label93;
                    }
                }

                if (this.oa || this.na) {
                    long var6 = super.D;
                    byte var11;
                    if (this.na) {
                        var11 = 1;
                    } else {
                        var11 = -1;
                    }

                    this.a(var6, var11);
                    super.o = 0.0D;
                    super.n = 0.0D;
                    super.D = 0L;
                    super.F = -1;
                }

                this.getParent().requestDisallowInterceptTouchEvent(false);
                this.oa = false;
                this.na = false;
            }
        } else {
            boolean var10;
            var10 = (double) Math.abs(var3 - (float) this.wa) < (double) this.sa / 2.0D;

            boolean var7;
            double var12;
            var7 = Math.abs((var12 = (double) var2) - this.qa) < (double) this.ta / 2.0D;

            boolean var13;
            var13 = Math.abs(var12 - this.ra) < (double) this.ta / 2.0D;

            if (var10 && var7) {
                this.na = true;
            } else if (var10 && var13) {
                this.oa = true;
            }
        }

        if (!this.oa && !this.na) {
            this.getParent().requestDisallowInterceptTouchEvent(false);
            return super.onTouchEvent(var1);
        } else {
            this.getParent().requestDisallowInterceptTouchEvent(true);
            return true;
        }
    }

    public double j() {
        return (double) this.i() / d.a(super.l) * super.m - super.n - super.o - (double) super.f;
    }

    public void a(int var1) {
        super.l = var1;
    }

    public void b(double var1) {
        super.b(var1);
        this.ia[0] = false;
    }

    void a(long var1, int var3) {
        SmartLog.i("handleCutEvent", "just display, do nothing event");
        this.ja = true;
    }

    public void a(int var1, int var2, MotionEvent var3) {
        SmartLog.i("handlecutAudio", "just display, do nothing event");
    }

    public void a(HAEAudioAsset var1) {
        super.speed = var1.getSpeed();
        this.a(var1);
        this.ia[0] = false;
        super.W = (long) Util.divideScale((float) var1.getTrimIn(), super.speed, 5);
        super.aa = var1.getTrimOut();
        super.startTime = var1.getStartTime();
        super.r = var1.getDuration();
        var1.getOriginLength();
        if (super.aa == 0L) {
            super.aa = super.r;
        }

        this.b(var1.getOriginLength());
        super.I.clear();
        this.ha.clear();
        if (var1.getFootPrintList().size() > 0) {
            this.ha.addAll(var1.getFootPrintList());
        }

        this.a(super.g);
    }

//    public void a(e var1) {
//    }
}
